<?php

/**
 * Auto Code generation
 *
 * @version $Rev:$
 * @license
 */
class Admin_Model_Roles extends Zend_Db_Table_Abstract
{

	protected $_name = 'role';
    protected $_primary = 'ROLEID';
	
    public function __construct($config = array())
    {
        parent::__construct($config);
		$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH.'/log.txt');
		$this->logger = new Zend_Log($writer);
    }
	
	public function selectAll(){
        $select = $this->select();
        $select->from($this,array('ROLEID','NAME','DESCRIPTION','NAVIGATION','STATUS'));
        $data = $this->fetchAll($select);
        return $data;
    }
	
    public function addNewRole($Params){
        $db = $this->getDefaultAdapter();
        
		$data = array(
            'NAME' => $Params['NAME'],
            'DESCRIPTION' => $Params['DESCRIPTION'],
            'STATUS' => (int) $Params['STATUS'],
            'NAVIGATION' => $Params['NAVIGATION'],
        );
        try{     
			$db->insert($this->_name, $data);
			return $db->lastInsertId('role','ROLEID');
		} catch(Zend_Exception $e) {
			echo $e->getMessage();
		}
		
		return 0;
    }
	
    public function updateRole($Params){
		$db = $this -> getDefaultAdapter();
		
		$where = $db->quoteInto('ROLEID = ?', $Params['ROLEID']);
		try{
			$db->update('role',$Params,$where);        
		} catch (Zend_Exception $e) {
			$this->logger->info($e->getMessage());
		}
    }
    
	public function deleteRole($itemID){
        try{
			$db = $this -> getDefaultAdapter();
			$db->delete("role","ROLEID=".(int)$itemID);
		} catch (Zend_Exception $e) {
			$this->logger->info($e->getMessage());
		}
    }
}

